<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BaseModel extends Model
{

    use HasFactory;

    protected $hidden = ['deleted_at'];

    /**
     * 通用属性:是否启用
     */
    const IS_ENABLE = [
        'disable' => ['value' => 0, 'label' => '禁用'],
        'enable'  => ['value' => 1, 'label' => '启用'],
    ];

    /**
     * 时间戳格式化
     * @param \DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * 获取属性值;
     * @param array $attrbiute
     * @return array
     */
    protected function getAttributeVal(array $attrbiute)
    {
        return array_column($attrbiute, 'label', 'value');
    }

    /**
     * 追加属性
     * @return mixed
     */
    public function getIsEnableTxAttribute()
    {
        return $this->getAttributeVal(self::IS_ENABLE)[$this->attributes['is_enable']];
    }
}
